package by.grsu.shedule.adapter;

import java.util.List;

import android.content.Context;
import android.view.View;
import android.widget.TextView;
import by.grsu.shedule.R;
import by.grsu.shedule.common.adapter.AbstractAdapter;
import by.grsu.shedule.database.ImportantLessonManager;
import by.grsu.shedule.model.DayFromDB;

public class DayAdapter extends AbstractAdapter<DayFromDB> {

	private static final String TAG = DayAdapter.class.getSimpleName();

	private Context mContext;

	private ImportantLessonManager importantLessonManager;
	
	private String lastTime;

	public DayAdapter(Context c, int pItemResource, List<DayFromDB> pList) {
		super(c, pItemResource, pList);
		mContext = c;
		importantLessonManager = (ImportantLessonManager) c
				.getApplicationContext().getSystemService(
						ImportantLessonManager.IMPORTANT_LESSON_MANAGER);
	}

	@Override
	public void init(View convertView, DayFromDB item) {

		TextView timeStart = (TextView) convertView
				.findViewById(R.id.timeStart);
		timeStart.setText(item.getTimeStart());
		TextView timeFinish = (TextView) convertView
				.findViewById(R.id.timeFinish);
		timeFinish.setText(item.getTimeFinish());

		TextView group = (TextView) convertView.findViewById(R.id.group);

		TextView subject = (TextView) convertView.findViewById(R.id.subject);

		TextView teacher = (TextView) convertView.findViewById(R.id.teacher);

		TextView auditory = (TextView) convertView.findViewById(R.id.auditory);

		if (item.getTeacher().length() != 0) {

			teacher.setText(item.getTeacher());
			subject.setText(item.getSubject());
			group.setText(item.getGroup());
			auditory.setText(item.getAuditory());
			if (importantLessonManager.getLesson(item.getSubject(),
					item.getTeacher(), item.getGroup())) {
				convertView.setBackgroundColor(mContext.getResources()
						.getColor(R.color.my));
			}

		} else {
			teacher.setText(mContext.getString(R.string.not_lesson));
			subject.setText("");
			group.setText("");
			auditory.setText("");
		}
		
	}

}
